package com.ohos.carbon.provider;

import com.ohos.carbon.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.app.Context;

import java.util.List;

public class Drop_Year_MonthProvider extends RecyclerAdapter<Drop_Year_MonthProvider.ViewHolder>{

    private List<String> mList;
    private Context context;

    public Drop_Year_MonthProvider(List<String> mList, Context context) {
        this.mList = mList;
        this.context = context;
    }

    @Override
    public RecyclerAdapter<ViewHolder>.ViewHolder onCreateViewHolder(ComponentContainer componentContainer) {
        Component component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_dropdown_item_one, componentContainer, false);
        return new ViewHolder(component);
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        ViewHolder viewHolder = holder;
        if (mList != null ) {
            viewHolder.text_content.setText(mList.get(position));
        }
        notifyDataInvalidated();
    }

    @Override
    public Object getItem(int i) {
        if (mList != null && i >= 0 && i < mList.size()) {
            return mList.get(i);
        }
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    class ViewHolder extends RecyclerAdapter.ViewHolder {
        private Text text_content;
        public ViewHolder(Component itemComponent) {
            super(itemComponent);
            text_content = (Text) itemComponent.findComponentById(ResourceTable.Id_dropdown_year_month);
        }
    }
}
